function [B Coords SuspiciousCoords] = chi_square_check( ...
    B, C, SuspiciousCoords, S, w, Coords, phiCoord, phiCov, phiSigma, coordsA)

global g_N;
global J;
global SHOW_HYST;

if B == 1
    return
end

nu = zeros(J, 1);
Prob = zeros(J, 1);

for j = 1:J
    nu(j) = sum(indicator(Coords, coordsA(j)));
    limits = coordsA(j);
    xl = limits(1, :);
    xu = limits(2, :);
    for s = 1:S
        Prob(j) = Prob(j) + w(s)*mvncdf(xl, xu, phiCoord(s, :), phiCov(:,:,s));
    end
end

% FIXME:
Prob = Prob + 1e-5;

C_ = sum( ((nu - g_N*Prob).^2)./(g_N*Prob));
if (C_ < C)
    fprintf('Критерий удовлетворен, Criteria = %f < %f\n', C_, C);
    B = 1;

    if (SHOW_HYST == 1)
        figure;
        hold on;
        grid on;
        title('\nu_j, P(A_{j}|\phi)');
        xlabel('j');
        stem(Prob, 'x', 'color', 'blue');
        stem(nu/g_N, '.', 'color', 'red');
        legend('P(A_{j}|\phi)', '\nu_j', 4);
    end
else
    fprintf('Критерий не удовлетворен, Criteria = %f > %f\n', C_, C);
    [Coords, SuspiciousCoords] = ...
        delete_too_far(S, SuspiciousCoords, Coords, w, phiCoord, phiSigma);
end

end